/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HopFrame.java
 *
 * Created on Mar 9, 2011, 3:59:47 PM
 */

package gbbmgmt;

import org.jdesktop.application.Action;
import java.util.*;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class HopFrame extends javax.swing.JFrame {

    public ArrayList<String[]> Hop;
    public ArrayList<String[]> Vendor;
    public ArrayList<String[]> StockCode;

    /** Creates new form HopFrame */
    public HopFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxHop = new javax.swing.JComboBox();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jButtonCustLast = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabelHopID = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldHopName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldHopAA = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldHopBagLbs = new javax.swing.JTextField();
        jCheckBoxHopWhole = new javax.swing.JCheckBox();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxVendor = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabelMaltOnHand = new javax.swing.JLabel();
        jLabelMaltSpoken = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jButtonUpdate = new javax.swing.JButton();
        jButtonNew = new javax.swing.JButton();
        jButtonSubmit = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        jLabelWearhouse = new javax.swing.JLabel();
        jLabelscode = new javax.swing.JLabel();
        jLabelStockCode = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jComboBoxHop.setName("jComboBoxHop"); // NOI18N
        jComboBoxHop.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxHopPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(HopFrame.class, this);
        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(HopFrame.class);
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("PrevRecord")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("NextRecord")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabelHopID.setText(resourceMap.getString("jLabelHopID.text")); // NOI18N
        jLabelHopID.setName("jLabelHopID"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldHopName.setText(resourceMap.getString("jTextFieldHopName.text")); // NOI18N
        jTextFieldHopName.setName("jTextFieldHopName"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldHopAA.setName("jTextFieldHopAA"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldHopBagLbs.setName("jTextFieldHopBagLbs"); // NOI18N

        jCheckBoxHopWhole.setText(resourceMap.getString("jCheckBoxHopWhole.text")); // NOI18N
        jCheckBoxHopWhole.setName("jCheckBoxHopWhole"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jComboBoxVendor.setName("jComboBoxVendor"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabelMaltOnHand.setText(resourceMap.getString("jLabelMaltOnHand.text")); // NOI18N
        jLabelMaltOnHand.setName("jLabelMaltOnHand"); // NOI18N

        jLabelMaltSpoken.setText(resourceMap.getString("jLabelMaltSpoken.text")); // NOI18N
        jLabelMaltSpoken.setName("jLabelMaltSpoken"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        jButtonUpdate.setAction(actionMap.get("UpdateHop")); // NOI18N
        jButtonUpdate.setText(resourceMap.getString("jButtonUpdate.text")); // NOI18N
        jButtonUpdate.setName("jButtonUpdate"); // NOI18N

        jButtonNew.setAction(actionMap.get("NewHop")); // NOI18N
        jButtonNew.setText(resourceMap.getString("jButtonNew.text")); // NOI18N
        jButtonNew.setName("jButtonNew"); // NOI18N

        jButtonSubmit.setAction(actionMap.get("SubmitHop")); // NOI18N
        jButtonSubmit.setText(resourceMap.getString("jButtonSubmit.text")); // NOI18N
        jButtonSubmit.setName("jButtonSubmit"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitHops")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabelWearhouse.setText(resourceMap.getString("jLabelWearhouse.text")); // NOI18N
        jLabelWearhouse.setName("jLabelWearhouse"); // NOI18N

        jLabelscode.setText(resourceMap.getString("jLabelscode.text")); // NOI18N
        jLabelscode.setName("jLabelscode"); // NOI18N

        jLabelStockCode.setText(resourceMap.getString("jLabelStockCode.text")); // NOI18N
        jLabelStockCode.setName("jLabelStockCode"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxHop, 0, 276, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelHopID, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 209, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelWearhouse)
                .addGap(18, 18, 18)
                .addComponent(jLabelscode)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelStockCode)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldHopAA, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(31, 31, 31)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldHopBagLbs, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addComponent(jCheckBoxHopWhole))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldHopName, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxVendor, 0, 438, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelMaltOnHand, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelMaltSpoken, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(305, Short.MAX_VALUE))
            .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonUpdate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSubmit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 166, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextFieldHopAA, jTextFieldHopBagLbs});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButtonCustLast)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustPrev)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jComboBoxHop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelHopID)
                    .addComponent(jLabelStockCode)
                    .addComponent(jLabelscode)
                    .addComponent(jLabelWearhouse)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldHopName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldHopAA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxHopWhole)
                    .addComponent(jTextFieldHopBagLbs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jComboBoxVendor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabelMaltOnHand))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabelMaltSpoken))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonUpdate)
                    .addComponent(jButtonNew)
                    .addComponent(jButtonSubmit)
                    .addComponent(jButtonExit))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxHopPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxHopPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxHop.getSelectedItem().toString();

        for(String s[] : Hop){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetHopsData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
}//GEN-LAST:event_jComboBoxHopPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new HopFrame().setVisible(true);
            }
        });
    }

    public void LoadList(){
        //Remove all vendors in list.
        jComboBoxHop.removeAllItems();

        DBA.openDBCon();
        Hop = DBA.RunSQLQuery("SELECT HID,HopName FROM Hops");
        Vendor = DBA.RunSQLQuery("SELECT VID,VName From Vendors");
        StockCode = DBA.RunSQLQuery("SELECT StockID,WHID,TableID From StockCode");
        DBA.closeDBCon();

        for(String s[] : Hop){
            jComboBoxHop.addItem(s[1]);
        }

        for(String s[] : Vendor){
            jComboBoxVendor.addItem(s[1]);
        }

        //Hide submit button.
        jButtonSubmit.setVisible(false);

        LastRecord();
    }

    @Action
    public void LastRecord() {
        jComboBoxHop.setSelectedIndex(jComboBoxHop.getItemCount()-1);

        String Itm = jComboBoxHop.getSelectedItem().toString();

        for(String s[] : Hop){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetHopsData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    public void SetData(){
        jLabelHopID.setText(Integer.toString(DBA.HID));
        jTextFieldHopName.setText(DBA.HopName);
        jTextFieldHopAA.setText(Float.toString(DBA.HopAA));
        jTextFieldHopBagLbs.setText(Float.toString(DBA.HopBagLbs));
        jCheckBoxHopWhole.setSelected(DBA.HopWhole);

        jLabelMaltOnHand.setText(Float.toString(DBA.HopOnHand) + " Lbs.");
        jLabelMaltSpoken.setText(Float.toString(DBA.HopSpoken) + " Lbs.");

        DBA.openDBCon();
        String scode = DBA.ReturnStockCode(jLabelWearhouse.getText(), jLabelHopID.getText());
        String StockNumber = String.format("%05d", Integer.parseInt(scode));
        DBA.GetStockCodeData(scode);
        DBA.closeDBCon();

        for(String s[] : Vendor){
            if (s[0].equals(Integer.toString(DBA.StockVendID))) {
                jComboBoxVendor.setSelectedItem(s[1]);
            }
        }

        jLabelStockCode.setText(StockNumber);
    }

    @Action
    public void FirstRecord() {
        jComboBoxHop.setSelectedIndex(0);

        String Itm = jComboBoxHop.getSelectedItem().toString();

        for(String s[] : Hop){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetHopsData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void NextRecord() {
        if(jComboBoxHop.getSelectedIndex() <= (jComboBoxHop.getItemCount()-2)){
            jComboBoxHop.setSelectedIndex(jComboBoxHop.getSelectedIndex()+1);
        }

        String Itm = jComboBoxHop.getSelectedItem().toString();

        for(String s[] : Hop){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetHopsData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void PrevRecord() {
        if(jComboBoxHop.getSelectedIndex()>=1){
            jComboBoxHop.setSelectedIndex(jComboBoxHop.getSelectedIndex()-1);
        }

        String Itm = jComboBoxHop.getSelectedItem().toString();

        for(String s[] : Hop){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetHopsData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void ExitHops() {
        dispose();
    }

    @Action
    public void NewHop() {
        //Show Submit button.
        jButtonSubmit.setVisible(true);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(false);
        jButtonNew.setVisible(false);
        jButtonCustFirst.setVisible(false);
        jButtonCustLast.setVisible(false);
        jButtonCustNext.setVisible(false);
        jButtonCustPrev.setVisible(false);
        jComboBoxHop.setVisible(false);
        jLabelHopID.setVisible(false);
        jLabel1.setVisible(false);
        jLabelStockCode.setVisible(false);
        jLabelscode.setVisible(false);

        //Set text in all fields to blank.
        jLabelHopID.setText("");
        jTextFieldHopName.setText("");
        jTextFieldHopAA.setText("");
        jTextFieldHopBagLbs.setText("");

        jCheckBoxHopWhole.setSelected(false);
        
        jLabelMaltOnHand.setText("0 Lbs.");
        jLabelMaltSpoken.setText("0 Lbs.");
    }

    @Action
    public void SubmitHop() {
        int response = JOptionPane.showConfirmDialog(null,
                "Warning, this record will be added to the database, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);
        if (response == 0){

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String fields = "HopName,HopAA,HopWhole,HopBagLbs";
            String query = "'" +
                jTextFieldHopName.getText() + "','" +
                jTextFieldHopAA.getText() + "','" +
                Integer.toString((jCheckBoxHopWhole.isSelected())?1:0) + "','" +
                jTextFieldHopBagLbs.getText() + "'";

            DBA.openDBCon();
            DBA.RunSQLInsertQuery("Hops",fields,query);
            //String MaID = DBA.GetLastIndex("Hops", "HID");
            String MaID = Integer.toString(Global.lastInsertID);
            DBA.closeDBCon();

            DBA.openDBCon();
            String WhID = "110";
            fields = "TableID,WHID,StockVendID";
            query = "'" + MaID + "','" + WhID + "','" + VID + "'";
            DBA.RunSQLInsertQuery("StockCode",fields,query);
            DBA.closeDBCon();
        }

        //Show Submit button.
        jButtonSubmit.setVisible(false);

        //Hide all appropriate buttons.
        jButtonUpdate.setVisible(true);
        jButtonNew.setVisible(true);
        jButtonCustFirst.setVisible(true);
        jButtonCustLast.setVisible(true);
        jButtonCustNext.setVisible(true);
        jButtonCustPrev.setVisible(true);
        jComboBoxHop.setVisible(true);
        jLabelHopID.setVisible(true);
        jLabel1.setVisible(true);
        jLabelStockCode.setVisible(true);
        jLabelscode.setVisible(true);

        LoadList();
    }

    @Action
    public void UpdateHop() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify hop data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            DBA.openDBCon();

            String vend = jComboBoxVendor.getSelectedItem().toString();
            String VID = "0";

            for(String s[] : Vendor){
                if (s[1].equals(vend)) {
                    VID = s[0];
                }
            }

            String HopID = jLabelHopID.getText();

            String query = "UPDATE Hops SET HopName='" +
                        jTextFieldHopName.getText() + "',HopAA='" +
                        jTextFieldHopAA.getText() + "',HopWhole='" +
                        Integer.toString((jCheckBoxHopWhole.isSelected())?1:0) + "',HopBagLbs='" +
                        jTextFieldHopBagLbs.getText() +"' WHERE HID = '" + HopID + "'";
            DBA.RunSQLUpdateQuery(query);

            int StID = Integer.parseInt(jLabelStockCode.getText());

            query = "UPDATE StockCode SET StockVendID='" +
                    VID + "' WHERE StockID = '" + Integer.toString(StID) + "'";
            DBA.RunSQLUpdateQuery(query);

            DBA.closeDBCon();
        }
    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonNew;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JButton jButtonUpdate;
    private javax.swing.JCheckBox jCheckBoxHopWhole;
    private javax.swing.JComboBox jComboBoxHop;
    private javax.swing.JComboBox jComboBoxVendor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelHopID;
    private javax.swing.JLabel jLabelMaltOnHand;
    private javax.swing.JLabel jLabelMaltSpoken;
    private javax.swing.JLabel jLabelStockCode;
    private javax.swing.JLabel jLabelWearhouse;
    private javax.swing.JLabel jLabelscode;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextFieldHopAA;
    private javax.swing.JTextField jTextFieldHopBagLbs;
    private javax.swing.JTextField jTextFieldHopName;
    // End of variables declaration//GEN-END:variables

}
